import time
from datetime import datetime
#1/time模块
#获得当前时间
#时间戳time.localtime()
#UTC时间就是通用时间，没有时区
print(time.time())
#时间格式转换
#time.struct_time---str
print(time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()))
print("str---time.struct_time")
print(time.strptime("2020-11-08  19:22:30","%Y-%m-%d %H:%M:%S"))
#time.struct_time---tuple
now = time.localtime()
print(now)
print(tuple(now))
#tuple------time.struct_time
print(time.struct_time(tuple(now)))
print(list(now))
#timestamp---time.struct_time
print(time.localtime(time.time()))#有时区
print(time.gmtime(time.time()))#无时区
#time.struct_time---timestamp
print(time.mktime(now))#时间精度丢失
print(time.time())
print(time.mktime(time.localtime()))
print("----------------------------------")
#2/datetime 提供了处理日期和时间的类
#查看时间
print(datetime.today())
print(datetime.now(tz = None))#指定时区
print(datetime.utcnow())
# print(datetime.now(offset = 8))
print("----------------------------------")
#datetime.datetime---str
now =datetime.now()
print(now.strftime("%Y-%m-%d %H:%M:%S"))
#str --datetime.datetime
now_str = now.strftime("%Y-%m-%d %H:%M:%S")
print(datetime.strptime(now_str, "%Y-%m-%d %H:%M:%S"))
#datetime.datetime---tuple
print(now.timetuple())
print(tuple(now.timetuple()))
#tuple--datetime.datetime
t =tuple(now.timetuple())
# print(datetime(t))
# print(datetime(*t))
new_t = t[:-3]
print(new_t)
print(*new_t)
#datetime=----timestamp
print(now)
print(now.timestamp())
#timestamp--datetime
print(datetime.fromtimestamp(now.timestamp()))
print("----------------------------------")
#时间运算
from datetime import timedelta
print(now)
print(now+timedelta(hours = 1))

print("--------------------------------------------------------------------")
#2/封装一个函数get_date(days) , 通过传入的数值days(days=1[-2,3,4,5]), 返回格式化后的时间
from datetime import datetime
from datetime import timedelta
def get_date(days):
    date_today = datetime.today()
    date_next = date_today + timedelta(days = days)
    print(f"Today is {date_today.strftime('%Y-%m-%d')}")
    time.sleep(2)
    print(f"After {days} days later ,it is {date_next.strftime('%Y-%m-%d')}")

get_date(5)


